package com.wangsd.web.report.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.MyController;
import com.wangsd.web.report.entity.ServiceBusiness;
import com.wangsd.web.report.service.ServiceBusinessService;
import com.wangsd.web.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author generator
 * @since 2019-09-05
 */
@Api(value = "serviceBusiness", tags = "服务商管理")
@RestController
@RequestMapping("/report/serviceBusiness")
@Slf4j
public class ServiceBusinessController extends MyController {
    @Autowired
    ServiceBusinessService serviceBusinessService;


    @ApiOperation(value = "查询服务商列表", notes = "查询服务商列表", httpMethod = "POST")
    @RequestMapping(value = "/selectList/{pageNum}/{pageSize}", method = RequestMethod.POST)
    public Result<IPage<ServiceBusiness>> selectList(@ApiParam(value = "当前页", required = true) @PathVariable("pageNum") Integer pageNum,
                                                     @ApiParam(value = "每页大小", required = true) @PathVariable("pageSize") Integer pageSize,
                                                     @RequestBody @ApiParam(name = "serviceBusiness", value = "传入json格式") ServiceBusiness serviceBusiness) {
        SysUser loginUser = getUserInfo();
        IPage<ServiceBusiness> serviceBusinessIPage = serviceBusinessService.selectList(pageNum, pageSize, serviceBusiness,loginUser.getCode());
        return Result.success(serviceBusinessIPage);
    }


    @ApiOperation(value = "新增或修改服务商", notes = "新增或修改服务商", httpMethod = "POST", response = Result.class)
    @RequestMapping(value = "addOrUpdate", method = RequestMethod.POST)
    public Result addOrUpdate(ServiceBusiness serviceBusiness) {
        serviceBusinessService.addOrUpdate(serviceBusiness);
        return Result.success();
    }

    @ApiOperation(value = "删除服务商信息", notes = "删除服务商信息", httpMethod = "GET", response = Result.class)
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public Result delete(@ApiParam(value = "用户id", required = true) @PathVariable("id") Long id) {
        serviceBusinessService.removeById(id);
        return Result.success();
    }

    @ApiOperation(value = "通过id查询服务商", notes = "通过id查询服务商", httpMethod = "GET", response = Result.class)
    @GetMapping("/selectById/{id}")
    public Result<ServiceBusiness> selectById(@ApiParam(value = "服务商id", required = true) @PathVariable Long id) {
        ServiceBusiness serviceBusiness = serviceBusinessService.getById(id);
        return Result.success(serviceBusiness);
    }

    @ApiOperation(value = "查询所有服务商", notes = "查询所有服务商", httpMethod = "GET", response = Result.class)
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public Result selectAll() {
        SysUser loginUser = getUserInfo();
        List<Map> list = serviceBusinessService.selectAllByUserCode(loginUser.getCode());
        return Result.success(list);
    }







}